package com.ksyun.campus.metaserver.controller;

import com.ksyun.campus.metaserver.biz.services.FsckServices;
import com.ksyun.campus.metaserver.entity.meta.StatInfo;
import com.ksyun.campus.metaserver.entity.meta.tree.FileTreeManager;
import com.ksyun.campus.metaserver.entity.server.DataServer;
import com.ksyun.campus.metaserver.entity.server.MetaServer;
import com.ksyun.campus.metaserver.util.ZooKeeperUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
public class TestController {

    private final FileTreeManager fileTreeManager;
    private final ZooKeeperUtil zooKeeperUtil;
    private final FsckServices fsckServices;
    @RequestMapping("/printFileTree")
    public void printFileTree(@RequestHeader String fileSystemName) {
        fileTreeManager.printFileTree(fileSystemName);
    }

    @RequestMapping("/getMetaServerList")
    public List<MetaServer> getMetaServerList(){
        return zooKeeperUtil.getMetaServerlist(zooKeeperUtil.ZK_META_SERVER_ROOT_PATH);
    }
    @RequestMapping("/getDataServerList")
    public List<DataServer> getDataServerList(){
        return zooKeeperUtil.getDataServerlist(zooKeeperUtil.ZK_DATA_SERVER_ROOT_PATH);
    }

    @RequestMapping("/fsck")
    public List<StatInfo> fsck(){
        return fsckServices.fsckTask();
    }
}
